import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

let router = new Router({
    //mode: 'history', //后端支持可开
    scrollBehavior: () => ({ y: 0 }),
    routes: [
		{
			path: '/',
			component: (resolve) => require(['@/view/layout'], resolve),
			children: [
				{
					path: '/',
					component: (resolve) => require(['@/view/work'], resolve)
				},
				{
					path: '/config',
					component: (resolve) => require(['@/view/config'], resolve),
				},
				{
					path: '/user/list',
					component: (resolve) => require(['@/view/user/list'], resolve)
				},
				{
					path: '/product/list',
					component: (resolve) => require(['@/view/product/list'], resolve)
				},
				{
					path: '/cate/list',
					component: (resolve) => require(['@/view/cate/list'], resolve),
				},
				{
					path: '/order/list',
					component: (resolve) => require(['@/view/order/list'], resolve)
				},
				{
					path: '/order/refund',
					component: (resolve) => require(['@/view/order/refund'], resolve)
				},
				{
					path: '/formorder/list',
					component: (resolve) => require(['@/view/formorder/list'], resolve),
				},
				{
					path: '/form/list',
					component: (resolve) => require(['@/view/form/list'], resolve),
				},
				{
					path: '/style/list',
					component: (resolve) => require(['@/view/style/list'], resolve),
				},
				{
					path: '/404',
					component: () => import('@/view/404'),
					hidden: true
				}
			]
		},
		{ path: '*', redirect: '/404', hidden: true }
	]
})

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}

export default router